package com.youyi.yychosesdk.models.sticker.view;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;

import com.lkx.liandianqinew.R;

public class EditFragment extends DialogFragment implements View.OnClickListener {
    private EditText et;
    private InputMethodManager inputMethodManager;
    private SeekBar seekBar;
    private TextSticker textSticker = null;
    private TextView tvSample;

    public static EditFragment show(FragmentManager fragmentManager, TextSticker textSticker2) {
        EditFragment editFragment = new EditFragment();
        editFragment.textSticker = textSticker2;
        editFragment.show(fragmentManager, "edit");
        return editFragment;
    }

    @Override // android.support.v4.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        getDialog().requestWindowFeature(1);
        View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_text_sticker_easy_photos, viewGroup);
        this.tvSample = (TextView) inflate.findViewById(R.id.tv_sample);
        this.et = (EditText) inflate.findViewById(R.id.et);
        this.seekBar = (SeekBar) inflate.findViewById(R.id.m_seek_bar);
        l(inflate, R.id.iv_red, R.id.iv_orange, R.id.iv_yellow, R.id.iv_green, R.id.iv_cyan, R.id.iv_blue, R.id.iv_purple, R.id.iv_black, R.id.iv_gray, R.id.iv_white, R.id.tv_done, R.id.iv_clear);
        this.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            /* class com.youyi.yychosesdk.models.sticker.view.EditFragment.AnonymousClass1 */

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
            }

            public void onProgressChanged(SeekBar seekBar, int i, boolean z) {
                if (z) {
                    EditFragment.this.setTextAlpha(i);
                }
            }
        });
        this.et.addTextChangedListener(new TextWatcher() {
            /* class com.youyi.yychosesdk.models.sticker.view.EditFragment.AnonymousClass2 */

            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public void afterTextChanged(Editable editable) {
                EditFragment.this.tvSample.setText(editable.toString());
                if (EditFragment.this.textSticker != null) {
                    EditFragment.this.textSticker.resetText(editable.toString());
                }
            }
        });
        return inflate;
    }

    private void l(View view, int... iArr) {
        for (int i : iArr) {
            view.findViewById(i).setOnClickListener(this);
        }
    }

    @Override // android.support.v4.app.Fragment
    public void onResume() {
        super.onResume();
        bindingSticker();
    }

    @Override // android.support.v4.app.Fragment, android.support.v4.app.DialogFragment
    public void onActivityCreated(Bundle bundle) {
        Window window = getDialog().getWindow();
        if (window != null) {
            WindowManager.LayoutParams attributes = window.getAttributes();
            attributes.flags |= 1024;
            window.setAttributes(attributes);
            window.requestFeature(1);
        }
        super.onActivityCreated(bundle);
        if (window != null) {
            window.setBackgroundDrawable(new ColorDrawable(0));
            window.setLayout(-1, -1);
            window.setSoftInputMode(16);
        }
    }

    public void bindingSticker() {
        String text = this.textSticker.getText();
        this.tvSample.setText(text);
        this.et.setText(text);
        this.et.setSelection(text.length());
        int textAlpha = this.textSticker.getTextAlpha();
        this.seekBar.setProgress(textAlpha);
        this.tvSample.setTextColor(this.textSticker.getTextColor());
        this.tvSample.setAlpha(((float) textAlpha) / 255.0f);
        InputMethodManager inputMethodManager2 = (InputMethodManager) getContext().getSystemService("input_method");
        this.inputMethodManager = inputMethodManager2;
        if (inputMethodManager2 != null) {
            inputMethodManager2.showSoftInput(this.et, 0);
        }
    }

    public void onClick(View view) {
        int id = view.getId();
        if (R.id.iv_red == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_red_easy_photos));
        } else if (R.id.iv_orange == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_orange_easy_photos));
        } else if (R.id.iv_yellow == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_yellow_easy_photos));
        } else if (R.id.iv_green == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_green_easy_photos));
        } else if (R.id.iv_cyan == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_cyan_easy_photos));
        } else if (R.id.iv_blue == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_blue_easy_photos));
        } else if (R.id.iv_purple == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_purple_easy_photos));
        } else if (R.id.iv_black == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_black_easy_photos));
        } else if (R.id.iv_gray == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_gray_easy_photos));
        } else if (R.id.iv_white == id) {
            setTextColor(ContextCompat.getColor(getContext(), R.color.text_sticker_white_easy_photos));
        } else if (R.id.tv_done == id) {
            dismiss();
        } else if (R.id.iv_clear == id) {
            this.et.setText((CharSequence) null);
        }
    }

    private void setTextColor(int i) {
        this.tvSample.setTextColor(i);
        this.textSticker.setTextColor(i);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setTextAlpha(int i) {
        this.tvSample.setAlpha(((float) i) / 225.0f);
        this.textSticker.setTextAlpha(i);
    }
}
